package com.shop.common.mapper;

import com.shop.common.core.basics.IBaseMapper;
import com.shop.common.entity.Credit;
import com.shop.common.enums.CreditActionEnum;
import org.apache.ibatis.annotations.Mapper;

/**
 * 学分记录Mapper
 */
@Mapper
public interface CreditMapper extends IBaseMapper<Credit> {
    /**
     * 增加学分日志
     */
    default void add(String userId, Integer paperId, Integer credit, CreditActionEnum actionEnum, String remark) {
        Credit model = new Credit();
        model.setUserId(userId);
        model.setPaperId(paperId);
        model.setCredit(credit);
        model.setAction(actionEnum.getCode());
        model.setCreateTime(System.currentTimeMillis() / 1000);
        model.setRemark(remark);
        insert(model);
    }
    default void add(String userId, Integer paperId, Integer credit, CreditActionEnum actionEnum) {
        add(userId, paperId, credit, actionEnum, null);
    }

    /**
     * 减少学分日志
     */
    default void reduce(String userId, Integer paperId, Integer credit, CreditActionEnum actionEnum, String remark) {
        add(userId, paperId, -credit, actionEnum, remark);
    }
    default void reduce(String userId, Integer paperId, Integer credit, CreditActionEnum actionEnum) {
        reduce(userId, paperId, credit, actionEnum, null);
    }
}
